package com.lyr.mumcock;

public class Child extends Thread{
    private Kitchen kitchen;
    // 体力值
    private int hp=0;
    // 健康值
    private int health;

    public Child(String name, Kitchen kitchen, int health) {
        super(name);
        this.kitchen = kitchen;
        this.health = health;
    }
    // 方法：吃饭

    public void eat() throws InterruptedException {
        this.kitchen.doeat();
    }

    @Override
    public void run() {
        //当体力值小于健康值，说明没有吃饱，可以一直进行吃饭操作，知道吃饱为止

        while (this.hp<this.health) {
            try {
                this.eat();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        System.out.println(this.getName()+"吃饱了，谢谢妈妈");
    }

    public int getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }
}
